package com.servlet.user;

import com.dao.UserDao;
import com.dao.UserInfo;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * @author admin
 */
@WebServlet(name = "UserSelectAllServlet",urlPatterns = "/UserSelectAllServlet.filter")
public class UserSelectAllServlet extends HttpServlet {
//    private String encoding;


    private UserDao userDao = new UserInfo();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("UserSelectAllServlet");
        try {
            List<User> userList = userDao.userAll();
            request.setAttribute("userList",userList);
            request.getRequestDispatcher("/WEB-INF/page/user.jsp").forward(request,response);
//           response.sendRedirect(request.getContextPath()+"/WEB-INF/page/user.jsp");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
